package com.example.testmixpanel;

import org.json.JSONException;
import org.json.JSONObject;

import com.mixpanel.android.mpmetrics.MixpanelAPI;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class MainActivity extends Activity {
	public static final String MIXPANEL_TOKEN = "83e1bb474ac4b4fded284ef055d0bdae";
	MixpanelAPI mixpanel;

	Button button;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

		button = (Button) findViewById(R.id.button1);

		// Initialize the library with your
		// Mixpanel project token, MIXPANEL_TOKEN, and a reference
		// to your application context.
		mixpanel = MixpanelAPI.getInstance(this, MIXPANEL_TOKEN);

		button.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				try {
					MixpanelAPI mixpanel = MixpanelAPI.getInstance(
							MainActivity.this, MIXPANEL_TOKEN);

					JSONObject props = new JSONObject();
					props.put("Gender", "Female");
					props.put("Plan", "Premium");

					mixpanel.track("555555555555555", props);
				} catch (JSONException e) {
					e.printStackTrace();
				}

			}

		});

	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

	@Override
	protected void onDestroy() {
		mixpanel.flush();
		super.onDestroy();

	}

}
